<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>电影订票购票系统</title>
    <link href="css/swiper-5.4.5/swiper.min.css" rel="stylesheet">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/my.css" rel="stylesheet">
    <style>
        .nx-nav-container ul{
            width: 100%;
            height: 100%;
            margin: 0 auto;
            display: flex;
            justify-content: center;
        }
        .nx-nav-container ul li{
            display: inline-block;
            width: 120px;
            text-align: center;
            line-height: 45px;
        }
        .nx-nav-container a{
            color: #FFFFFF;
        }
        .nx-nav-container a:hover {
            color: aquamarine;
            text-decoration: none;
        }
        .swiper-slide img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .nx-classify-container li{
            padding: 10px;
            text-align: center;
            border-bottom: 1px dashed #ccc;
            font-size: 14px;
            cursor: pointer;
        }
        .nx-classify-container li.active{
            color: #007aff;
            background-color: #ddd;
        }
        .nx-goods-container li img {
            width: 100%;
            height: 100%;
        }
        .direct{
            color: gray;
            cursor: pointer;
            margin: 5px;
            font-size: 20px;
        }
    </style>
</head>
<body>
<div id="wrapper">
    <div style="text-align: right;">
        <iframe width="700" scrolling="no" height="60" frameborder="0" src="https://i.tianqi.com/index.php?c=code&amp;id=12&amp;num=5"></iframe>
    </div>
    <div class="nx-header">
        <div style="display: flex;width: 100%;height: 30px;line-height: 30px;background-color: #eee;">
            <div style="flex: 5;padding: 0 10px; color: orangered;">
                欢迎访问 电影订票购票系统
            </div>
            <div v-if="user.name" style="flex: 1">
                欢迎您： {{user.name}}
                <a style="margin-left: 30px;color: blue;" href="javascript:void(0);" @click="logout">退出</a>
            </div>
        </div>
    </div>
    <div style="height: 80px; line-height: 80px;">
        <div style="margin-left: 20px;position: relative;">
            <img src="img/logo1.png" style="width: 40px;position: absolute;top: 20px;">
            <b style="margin-left: 45px;font-size:25px;text-shadow: 5px 5px 3px #888888">电影订票购票系统</b>
            <input type="text" style="position: absolute;right: 0;top: 30px;height: 30px;margin-right: 20px;"
                   placeholder="请输入商品关键字查询" v-model="searchText" @keyup.enter="searchGoods">
        </div>
    </div>
    <div class="nx-nav-container" style="height: 45px;background-color: black;">
        <ul>
            <li class="active"><a href="index.html">首页</a></li>
            <li><a href="advertiserInfo.html">公告信息</a></li>
            <li><a href="messageInfo.html">在线交流信息</a></li>
            <li><a href="linkInfo.html">友情链接</a></li>
            <li><a href="cartInfo.html">收藏栏信息</a></li>
            <li><a href="orderInfo.html">订单信息</a></li>
            <li><a href="commonInfo.html">评价信息</a></li>
            <li><a href="javascript:void(0)" @click="personalPage">个人信息</a></li>
            <li v-if="isShow"><a href="/end/page/index.html" target="_blank">进入后台系统</a></li>
            <li v-if="!isLogin"><a href="/end/page/login.html" target="_blank">登录</a></li>
            <li v-if="!isLogin"><a href="/end/page/register.html" target="_blank">注册</a></li>
        </ul>
    </div>

    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide">
                <img class="carousel-img" src="img/carousel/6.jpg">
            </div>
            <div class="swiper-slide">
                <img class="carousel-img" src="img/carousel/5.jpg">
            </div>
            <div class="swiper-slide">
                <img class="carousel-img" src="img/carousel/4.jpg">
            </div>
        </div>
        <div class="swiper-pagination">

        </div>
        <div class="swiper-button-prev">

        </div>
        <div class="swiper-button-next">

        </div>
    </div>
    <div style="margin-top: 5px;display: flex;">
        <!-- 电影分类 -->
        <div style="width: 12%;margin: 0 10px;height: 600px;border: 1px solid #ccc">
            <div style="height: 40px; background-color: #ccc">
                <div style="width: 100%;height:40px;margin-left: 10px;font-size: 20px;line-height:40px;text-align: center;color: white;background-color: red">
                    <b>电影分类</b>
                </div>
            </div>
            <div class="nx-classify-container">
                <ul>
                    <li v-for="(item, index) in typeObjs" :class="{active: index === activeIndex}" @click="findByTypeId(index, item.id)">
                        {{item.name}}
                    </li>
                </ul>
            </div>
        </div>
        <!-- 电影展示 -->
        <div style="width: 65%;border: 1px solid #ccc">
            <div style="height: 40px;background-color: #ccc">
                <div style="width: 100%;height: 40px;font-size: 20px;line-height: 40px;text-align: center;color: white;background-color: red">
                    <b>电影展示</b>
                </div>
            </div>
            <div style="padding: 10px;font-size: 14px">
                <ul class="nx-goods-container">
                    <li v-for="item in goodsList">
                        <a :href="'/front/goodsInfo.html?goodsId=' + item.id" target="_blank">
                            <div>
                                <img :src=item.src style="height: 220px">
                            </div>
                            <div style="font-seze: 14px;text-align: center">
                                {{item.name}}
                            </div>
                            <div style="font-seze: 14px;text-align: center;color: red">
                                ￥{{item.price}}
                            </div>
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        <!-- 右侧 -->
        <div style="width: 20%;height: 600px;">
            <div style="width: 100%;height: 300px;border: 1px solid #ccc;margin: 0 10px;position: relative  ">
                <div style="height: 40px;background-color: #ccc">
                    <div style="width: 100%;height: 40px;font-size: 20px;line-height: 40px;text-align: center;color: white;background-color: red">
                        <b>热门电影</b>
                    </div>
                </div>
                <div style="padding: 10px;font-size: 14px">
                    <ul style="padding: 10px;line-height: 30px;font-size: 14px;">
                        <li v-for="item in goodsList" style="margin: 5px auto">
                            <a :href="'/front/goodsInfo.html?goodsId=' + item.id" target="_blank">
                                {{item.name}}--{{item.actor}}
                            </a>
                        </li>
                    </ul>
                    <div style="text-align: center;position: absolute;bottom: 0;width: 100%">
                        <span class="direct" @click="recommend('left')"><</span>
                        <span class="direct" @click="recommend('right')">></span>
                    </div>
                </div>
            </div>
            <div style="width: 100%;height: 300px;border: 1px solid #ccc;margin: 0 10px;position: relative  ">
                <div style="height: 40px;background-color: #ccc">
                    <div style="width: 100%;height: 40px;font-size: 20px;line-height: 40px;text-align: center;color: white;background-color: red">
                        <b>热映电影</b>
                    </div>
                </div>
                <div style="padding: 10px;font-size: 14px">
                    <ul style="padding: 10px;line-height: 30px;font-size: 14px;">
                        <li v-for="item in hots" style="margin: 5px auto">
                            <a :href="'/front/goodsInfo.html?goodsId=' + item.id" target="_blank">
                                {{item.name}}--{{item.actor}}
                            </a>
                        </li>
                    </ul>
                    <div style="text-align: center;position: absolute;bottom: 0;width: 100%">
                        <span class="direct" @click="hotSales('left')"><</span>
                        <span class="direct" @click="hotSales('right')">></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery-1.10.2.js"></script>
<script src="js/swiper-5.4.5/swiper.min.js"></script>
<script src="js/vue2.6.11/vue.min.js"></script>
<script src="js/vue2.6.11/axios.js"></script>
<script src="js/my.js"></script>
<script>
    function msg(type,msg) {
        Vue.prototype.$message({
            type: type,      //success(成功),warning(警告),error(错误)
            message: msg,
            duration: 2000,
            offset: 100,
            center: true
        });
    }
    $(function () {
        var mySwiper = new Swiper('.swiper-container', {
            autoplay: {
                delay: 2000,
                disableOnInteraction: false
            },
            loop: true,
            speed: 2000,
            // 分页
            pagination:{
                el: '.swiper-pagination',
                clickable: true
            },
            // 前进后退按钮
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev'
            }
        });
        // 鼠标移入停止自动滚动
        var $swiperSlide = $('.swiper-slide');
        $swiperSlide.mouseenter(function() {
            mySwiper.autoplay.stop();
        });
        // 鼠标移出开始自动滚动
        $swiperSlide.mouseleave(function() {
            mySwiper.autoplay.start();
        });
    });
    new Vue({
        el: "#wrapper",
        data: {
            user: {}, // 当前登录用户
            searchText: "", // 商品关键字
            isShow: false, // 是否显示进入后台
            isLogin: false, // 是否登录
            typeObjs: [], // 所有电影类型列表
            activeIndex: 0, // 当前选择的电影类型
            goodsList: [], // 根据类型查询到的电影列表
            recommends:[], //热门电影
            recommendPages: 1, //热门电影总页数
            recommendPage: 1, //热门电影当前页
            hots: [], //热映电影
            salesPages: 1, //热映电影总页数
            salesPage: 1, //热映电影当前页
        },
        created: function () {
            // 查询权限
            axios.get('/auth').then(res =>{
                if(res.data.code == '0'){
                    this.user = res.data.data;
                    // 若是管理员
                    if(this.user.level === 1){
                        // 显示可以进入后台
                        this.isShow = true;
                    }
                    this.isLogin = true;
                }
            });
            // 查询所有电影类型列表
            axios.get("/typeInfo").then(res =>{
                this.typeObjs = res.data.data;
                this.findByTypeId(0, this.typeObjs[0].id);
            });
            this.loadRecommends(1);
            this.loadHots(1);
        },
        methods: {
            logout(){
                axios.get('/logout').then(res =>{
                    if(res.data.code === '0'){
                        location.href = '/front/index.html';
                    }else{
                        msg('error', res.data.msg);
                    }
                });
            },
            // 根据关键字搜索商品
            searchGoods() {
                if (this.searchText) {
                    axios.get('/goodsInfo/searchGoods', { params: { text: this.searchText } }).then((res) => {
                        if (res.data.code === '0') {
                            this.goodsList = res.data.data;
                            this.goodsList.forEach((item) => {
                                let imgSrc = "/front/img/goods/default.png";
                                if (item.fields) {
                                    let fileId = JSON.parse(item.fields)[0];
                                    imgSrc = "/files/download/" + fileId;
                                }
                                item.src = imgSrc;
                            });
                            this.activeIndex = null;
                        } else {
                            msg('error', res.data.msg);
                        }
                    });
                }else{
                    this.findByTypeId(0,this.typeObjs[0].id);
                   }
            },
            // 根据电影类型查询最新的10条电影数据
            findByTypeId(index, typeId){
                this.activeIndex = index;
                axios.get("/goodsInfo/findByTypeId/" + typeId).then(res =>{
                    if(res.data.code === '0'){
                        this.goodsList = res.data.data;
                        this.goodsList.forEach(item => {
                            let imgSrc = "/front/img/goods/default.png";
                            if(item.fields){
                                let fileId = JSON.parse(item.fields)[0];
                                imgSrc = "/files/download/" + fileId;
                            }
                            item.src = imgSrc;
                        });
                    }else{
                        msg('error', res.data.msg);
                    }
                });
            },
            //获取热门电影
            loadRecommends(pageNum){
                axios.get("/goodsInfo/recommend?pageNum="+pageNum).then(res =>{
                    if(res.data.code ==='0'){
                        this.recommends = res.data.data.list;
                         this.recommendPages = Math.ceil(res.data.data.total / 6); //热门电影总页数向上取整
                    }else{
                        msg('error',res.data.msg);
                    }
                });
            },
            //热门电影翻页，left转向上一页，right转向下一页
            recommend(direct){
                if(direct === 'left'){
                    this.recommendPage = this.recommendPage === 1 ? 1: (this.recommendPage - 1 );
                }else{
                    this.recommendPage = (this.recommendPage === this.recommendPages) ? this.recommendPages : (this.recommendPage + 1);
                }
                this.loadRecommends(this.recommendPage);
            },
            //获取热映电影
            loadHots(pageNum){
                axios.get("/goodsInfo/hotSales?pageNum="+pageNum).then(res =>{
                    if(res.data.code ==='0'){
                        this.hots = res.data.data.list;
                        this.salesPages = Math.ceil(res.data.data.total / 6); //热映电影总页数向上取整
                    }else{
                        msg('error',res.data.msg);
                    }
                });
            },
            //热映电影翻页，left转向上一页，right转向下一页
            hotSales(direct){
                if(direct === 'left'){
                    this.salesPage = this.salesPage === 1 ? 1: (this.salesPage - 1 );
                }else{
                    this.salesPage = (this.salesPage === this.salesPage) ? this.salesPage : (this.salesPage + 1);
                }
                this.loadHots(this.salesPage);
            },
        }
    });
</script>
</body>
</html>